package com.project.controller;

import com.project.entity.Management;
import com.project.entity.RestPOJO;
import com.project.service.impl.ManagementServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Api(tags = "物业管理")
@RestController
public class ManagementController {
    @Autowired
    private ManagementServiceImpl managementService;

    @ApiOperation(
            value = "获取所有物业信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/managements")
    public RestPOJO getAllManagement(){
        RestPOJO restPOJO = new RestPOJO();
        List<Management> list =  managementService.getAllManagement();
        if (list.size()>0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("查询成功");
            restPOJO.setData(list);
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("查询失败");
        }
        return restPOJO;
    }
    @ApiOperation(
            value = "用过用户ID获取物业信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @ApiImplicitParams({
            //如果是json，指定paramType为body
            @ApiImplicitParam(paramType="path",name="id",value="用户ID",required=true)
    })
    @GetMapping("/managementsbyUid/{id}")
    public RestPOJO getManagementByUid(@PathVariable("id") Integer uid){
        RestPOJO restPOJO = new RestPOJO();
        List<Management> list =  managementService.getManagementByUid(uid);
        if (list.size()>0){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("查询成功");
            restPOJO.setData(list);
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("查询失败");
        }
        return restPOJO;
    }
}
